extends "res://Weapon/scripts/WeaponCommon.gd"

@onready var bullet = load("res://Bullet/tscn/Bullet.tscn")

func fire():
	# 子弹伤害 = 子弹伤害 * 玩家伤害倍率
	power = bulletPower * state.power
	if !isFire:
		audio.play()
		fireTimer.start()
		# 每次开火都创建一个子弹场景
		var bullet = self.bullet.instantiate()
		# 为子弹复制属性
		bullet.speed = self.bulletSpeed
		bullet.power = self.power
		# 修改子弹的初始位置
		bullet.position = shootPosition.global_position
		# 子弹飞行方向
		# 勾股定理
		var direction = get_global_mouse_position() - global_position
		direction = direction.normalized()
		
		bullet.direction = direction
		get_tree().root.add_child(bullet)
	isFire = true
